package nah;

import static org.junit.Assert.assertTrue;
import nah.test.RobotTestBed;
import robocode.control.events.BattleCompletedEvent;
import robocode.control.events.TurnEndedEvent;
import robocode.control.snapshot.IScoreSnapshot;
import robocode.control.snapshot.ITurnSnapshot;

/**
 * Illustrates JUnit testing of Robocode robots. This test simply verifies that KillaRobot at least
 * hits the enemy robot. 
 * 
 * @author Nathaniel Ashe
 * 
 */
public class TestKillaRobotBulletHit extends RobotTestBed {

  ITurnSnapshot snapshot;
  boolean shot = false;

  /**
   * Specifies that Corners and KillaRobot are to be matched up in this test case.
   * 
   * @return The comma-delimited list of robots in this match.
   */
  @Override
  public String getRobotNames() {
    return "sample.Corners,nah.KillaRobot";
  }

  /**
   * This test runs for 10 rounds.
   * 
   * @return The number of rounds.
   */
  @Override
  public int getNumRounds() {
    return 10;
  }

  /**
   * Checks to see if KillaRobot hits Corners at least once.
   * 
   * @param event Details about the completed turn.
   */
  @Override
  public void onTurnEnded(TurnEndedEvent event) {
    int score = 0;
    snapshot = event.getTurnSnapshot();

    for (IScoreSnapshot damage : snapshot.getSortedTeamScores()) {
      // Gets the bullet hit damage score.
      score = (int) damage.getCurrentBulletDamageScore();
    }

    // Shot becomes true when the score is greater than 0.
    if (score > 0) {
      shot = true;
    }

  }

  /**
   * The actual test, which asserts that KillaRobot shot the enemy.
   * 
   * @param event Details about the completed battle.
   */
  @Override
  public void onBattleCompleted(BattleCompletedEvent event) {
    assertTrue("Check Damage", shot);
  }
}
